package com.zxx.coolweather;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;

import com.zxx.coolweather._wuguan.IDataListener;
import com.zxx.coolweather._wuguan.Volley;
import com.zxx.coolweather._wuguan2.NoHttpActivity;
import com.zxx.coolweather._wuguan3_ok.OkHttpActivity;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        if (prefs.getString("weather", null) != null) {
            Intent intent = new Intent(this, WeatherActivity.class);
            startActivity(intent);
            finish();
        }


        //testVolley();
    }

    private void testVolley() {
        String url = "http://guolin.tech/api/weather?cityid=CN101210106&key=bc0418b57b2d4918819d3974ac1285d9";
        //        String url = "https://www.wanandroid.com/banner/json";
        Volley.sendJsonRequest(null, url, "GET", String.class, new IDataListener<String>() {
            @Override
            public void onSuccess(String s) {
                Log.e("Tag-->", "响应：" + s);
            }

            @Override
            public void onFailure() {
                Log.e("Tag-->", "响应失败！！！");
            }
        });
    }

    //----------------------------------------------------
    public void jumpNoHttp(View view) {
        Intent intent = new Intent(this, NoHttpActivity.class);
        startActivity(intent);
    }

    public void jumpOkHttp(View view) {
        Intent intent = new Intent(this, OkHttpActivity.class);
        startActivity(intent);
    }
}
